using System;
using System.Collections.Generic;
using System.Text;
using Oracle.ManagedDataAccess.Client;
using OracleInternal.Common;
using OracleInternal.Core;

namespace Oracle.ManagedDataAccess.Types
{
	internal static class DecimalConv
	{
		internal const int LNXSGNBT = 128;

		internal const int LNXBASE = 100;

		private static char[] exponent = new char[2]
		{
			'E',
			'e'
		};

		private static char[] dot = new char[1]
		{
			'.'
		};

		private const string ZERO = "0";

		private const string INFINITY = "~";

		internal const int MAX_BYTEREP_LENGTH = 21;

		private const int POSITIVE_OFFSET = 1;

		private const int NEGATIVE_OFFSET = 101;

		private const byte NEGATIVE_BYTE_TERMINATOR = 102;

		private const byte MAX_EXPONENT = 127;

		private const byte BASE100EXP = 2;

		private const int ORANUM_MAX_EXP = 62;

		private const int ORANUM_MIN_EXP = -65;

		private const int ORANUM_POS_BASE = 100;

		private const int ORANUM_NEG_BASE = 2;

		private const int ORANUM_MAX_DIGITS = 40;

		internal static int GetPrecision(byte[] bytes, int dataPos, int length)
		{
			if (length == 1)
			{
				return 0;
			}
			if ((bytes[dataPos + 1] & 0x80u) != 0 && bytes[dataPos + 1] == byte.MaxValue && bytes[dataPos + 2] == 101)
			{
				return 0;
			}
			int num = (((bytes[dataPos] & 0x80) > 0) ? (bytes[dataPos + 1] - 1) : (101 - bytes[dataPos + 1]));
			return (length - 2) * 2 + ((num <= 9) ? 1 : 2);
		}

		internal static decimal GetDecimal(byte[] bytes, int dataPos, int length)
		{
			if (ProviderConfig.m_bTraceLevelPrivate)
			{
				Trace.Write(OracleTraceLevel.Private, OracleTraceTag.Entry, OracleTraceClassName.DecimalConv, OracleTraceFuncName.GetDecimal);
			}
			try
			{
				int num = dataPos + 1;
				if ((bytes[dataPos] & 0x80u) != 0)
				{
					int num2 = bytes[dataPos] - 193;
					if (length == 1)
					{
						return 0m;
					}
					if (bytes[dataPos] == byte.MaxValue && bytes[num] == 101)
					{
						throw new OverflowException();
					}
					if (num2 > 14 || (num2 == 14 && bytes[num] > 8) || num2 - (length - 2) < -14)
					{
						throw new OverflowException();
					}
					int num3 = (length - 1) * 2;
					if (num3 >= 32)
					{
						throw new OverflowException();
					}
					byte b = 0;
					if (num3 == 30)
					{
						if (bytes[num] - 1 < 10)
						{
							num3--;
						}
						if ((bytes[dataPos + length - 1] - 1) % 10 == 0)
						{
							num3--;
							b = (byte)((bytes[dataPos + length - 1] - 1) / 10);
						}
						if (num3 > 38)
						{
							throw new OverflowException();
						}
					}
					decimal num4 = default(decimal);
					int num5 = 0;
					int[] array = new int[4];
					int num6 = 1;
					int num7 = 1;
					int num8 = 1;
					int num9 = 1;
					int num10 = 0;
					int num11 = length;
					num10 = ((b <= 0) ? (2 * (num2 - (length - 2))) : (2 * (num2 - (length - 2)) + 1));
					if (num10 > 1)
					{
						num11 = num2 + 2;
					}
					int num12 = num11;
					int num13 = num11;
					if (num11 - 1 > 12)
					{
						if (b > 0)
						{
							array[0] = b;
							num12--;
							num6 = 10;
						}
						while (num12 >= num13 - 3)
						{
							num5 = ((num12 <= length) ? ((bytes[num12 + (dataPos - 1)] - 1) * num6) : 0);
							num6 *= 100;
							array[0] += num5;
							num12--;
						}
					}
					if (num11 - 1 > 8)
					{
						num13 = num12;
						while (num12 >= num13 - 3)
						{
							num5 = ((num12 <= length) ? ((bytes[num12 + (dataPos - 1)] - 1) * num7) : 0);
							num7 *= 100;
							array[1] += num5;
							num12--;
						}
					}
					if (num11 - 1 > 4)
					{
						num13 = num12;
						while (num12 >= num13 - 3)
						{
							num5 = ((num12 <= length) ? ((bytes[num12 + (dataPos - 1)] - 1) * num8) : 0);
							num8 *= 100;
							array[2] += num5;
							num12--;
						}
					}
					while (num12 >= 2)
					{
						num5 = ((num12 <= length) ? ((bytes[num12 + (dataPos - 1)] - 1) * num9) : 0);
						num9 *= 100;
						array[3] += num5;
						num12--;
					}
					num4 = ((num11 - 1 > 12) ? ((decimal)((long)array[3] * (long)num8 + array[2]) * (decimal)((long)num6 * (long)num7) + (decimal)((long)array[1] * (long)num6 + array[0])) : ((num11 - 1 > 8) ? ((decimal)((long)array[3] * (long)num8 + array[2]) * (decimal)num7 + (decimal)array[1]) : ((num11 - 1 <= 4) ? ((decimal)array[3]) : ((decimal)((long)array[3] * (long)num8 + array[2])))));
					if (num10 < 0)
					{
						if (num4 % 10m == 0m)
						{
							num4 /= 10m;
							num10++;
						}
						int[] bits = decimal.GetBits(num4);
						num4 = new decimal(bits[0], bits[1], bits[2], isNegative: false, (byte)(-num10));
					}
					else if (num10 == 1)
					{
						num4 *= 10m;
					}
					return num4;
				}
				int num14 = 62 - bytes[dataPos];
				if (length == 1)
				{
					throw new OverflowException();
				}
				if (num14 > 14 || (num14 == 14 && bytes[num] < 94) || num14 - (length - 3) < -14)
				{
					throw new OverflowException();
				}
				int num15 = (length - 2) * 2;
				if (num15 >= 32)
				{
					throw new OverflowException();
				}
				byte b2 = 0;
				if (num15 == 30)
				{
					if (101 - bytes[num] < 10)
					{
						num15--;
					}
					if ((101 - bytes[dataPos + length - 2]) % 10 == 0)
					{
						num15--;
						b2 = (byte)((101 - bytes[dataPos + length - 2]) / 10);
					}
					if (num15 > 38)
					{
						throw new OverflowException();
					}
				}
				decimal num16 = default(decimal);
				int num17 = 0;
				int[] array2 = new int[4];
				int num18 = 1;
				int num19 = 1;
				int num20 = 1;
				int num21 = 1;
				int num22 = 0;
				int num23 = length;
				num22 = ((b2 <= 0) ? (2 * (num14 - (length - 3))) : (2 * (num14 - (length - 3)) + 1));
				if (num22 > 1)
				{
					num23 = num14 + 3;
				}
				int num24 = num23 - 1;
				int num25 = num23 - 1;
				if (num23 - 2 > 12)
				{
					if (b2 > 0)
					{
						array2[0] = b2;
						num24--;
						num18 = 10;
					}
					while (num24 >= num25 - 3)
					{
						num17 = ((num24 < length) ? ((101 - bytes[num24 + (dataPos - 1)]) * num18) : 0);
						num18 *= 100;
						array2[0] += num17;
						num24--;
					}
				}
				if (num23 - 2 > 8)
				{
					num25 = num24;
					while (num24 >= num25 - 3)
					{
						num17 = ((num24 < length) ? ((101 - bytes[num24 + (dataPos - 1)]) * num19) : 0);
						num19 *= 100;
						array2[1] += num17;
						num24--;
					}
				}
				if (num23 - 2 > 4)
				{
					num25 = num24;
					while (num24 >= num25 - 3)
					{
						num17 = ((num24 < length) ? ((101 - bytes[num24 + (dataPos - 1)]) * num20) : 0);
						num20 *= 100;
						array2[2] += num17;
						num24--;
					}
				}
				while (num24 >= 2)
				{
					num17 = ((num24 < length) ? ((101 - bytes[num24 + (dataPos - 1)]) * num21) : 0);
					num21 *= 100;
					array2[3] += num17;
					num24--;
				}
				num16 = ((num23 - 2 > 12) ? ((decimal)((long)array2[3] * (long)num20 + array2[2]) * (decimal)((long)num18 * (long)num19) + (decimal)((long)array2[1] * (long)num18 + array2[0])) : ((num23 - 2 > 8) ? ((decimal)((long)array2[3] * (long)num20 + array2[2]) * (decimal)num19 + (decimal)array2[1]) : ((num23 - 2 <= 4) ? ((decimal)array2[3]) : ((decimal)((long)array2[3] * (long)num20 + array2[2])))));
				if (num22 < 0)
				{
					if (num16 % 10m == 0m)
					{
						num16 /= 10m;
						num22++;
					}
					int[] bits2 = decimal.GetBits(num16);
					num16 = new decimal(bits2[0], bits2[1], bits2[2], isNegative: true, (byte)(-num22));
				}
				else
				{
					int[] bits3 = decimal.GetBits(num16);
					bits3[3] |= int.MinValue;
					num16 = new decimal(bits3);
					if (num22 == 1)
					{
						num16 *= 10m;
					}
				}
				return num16;
			}
			catch (Exception ex)
			{
				OracleException.HandleError(OracleTraceLevel.Private, OracleTraceTag.Error, OracleTraceClassName.DecimalConv, OracleTraceFuncName.GetDecimal, ex);
				throw;
			}
			finally
			{
				if (ProviderConfig.m_bTraceLevelPrivate)
				{
					Trace.Write(OracleTraceLevel.Private, OracleTraceTag.Exit, OracleTraceClassName.DecimalConv, OracleTraceFuncName.GetDecimal);
				}
			}
		}

		internal static void GetBytes(decimal dec, out byte[] bytes)
		{
			if (ProviderConfig.m_bTraceLevelPrivate)
			{
				Trace.Write(OracleTraceLevel.Private, OracleTraceTag.Entry, OracleTraceClassName.DecimalConv, OracleTraceFuncName.GetBytes);
			}
			try
			{
				bytes = new byte[22];
				if (dec == 0m)
				{
					bytes[0] = 1;
					bytes[1] = 128;
					return;
				}
				int[] bits = decimal.GetBits(dec);
				int num = bits[3];
				bool flag = false;
				if ((num & 0x80000000u) == 2147483648u)
				{
					flag = true;
				}
				int num2 = (byte)((num & 0xFF0000) >> 16);
				decimal d = new decimal(10000000000000000L);
				int num3 = 100000000;
				decimal d2 = default(decimal);
				long num4 = 0L;
				long num5 = 0L;
				int num6 = 0;
				int num7 = 0;
				int num8 = 0;
				int num9 = 0;
				if (num2 == 0)
				{
					num4 = (long)(dec % d);
					num5 = (long)(dec / d);
					num6 = (int)(num4 % num3);
					num7 = (int)(num4 / num3);
					if (num5 != 0L)
					{
						num8 = (int)(num5 % num3);
						num9 = (int)(num5 / num3);
					}
					if (flag)
					{
						if (num6 < 0)
						{
							num6 = -num6;
						}
						if (num7 < 0)
						{
							num7 = -num7;
						}
						if (num8 < 0)
						{
							num8 = -num8;
						}
						if (num9 < 0)
						{
							num9 = -num9;
						}
					}
				}
				else
				{
					d2 = new decimal(bits[0], bits[1], bits[2], flag, 0) / (decimal)Math.Pow(10.0, num2);
					bits = decimal.GetBits(d2);
					num2 = (byte)((bits[3] & 0xFF0000) >> 16);
					d2 = new decimal(bits[0], bits[1], bits[2], isNegative: false, 0);
					if (num2 == 0)
					{
						num4 = (long)(d2 % d);
						num5 = (long)(d2 / d);
						num6 = (int)(num4 % num3);
						num7 = (int)(num4 / num3);
						if (num5 > 0)
						{
							num8 = (int)(num5 % num3);
							num9 = (int)(num5 / num3);
						}
					}
				}
				byte b = 100;
				byte b2 = 0;
				byte b3 = 0;
				byte b4 = 0;
				if (num2 == 0)
				{
					if (num6 > 0)
					{
						b4 = (byte)(num6 % (int)b);
						num6 /= (int)b;
						while (b4 == 0)
						{
							b4 = (byte)(num6 % (int)b);
							num6 /= (int)b;
							b2 = (byte)(b2 + 1);
						}
					}
					else if (num7 > 0)
					{
						b4 = (byte)(num7 % (int)b);
						num7 /= (int)b;
						b2 = 4;
						while (b4 == 0)
						{
							b4 = (byte)(num7 % (int)b);
							num7 /= (int)b;
							b2 = (byte)(b2 + 1);
						}
					}
					else if (num8 > 0)
					{
						b4 = (byte)(num8 % (int)b);
						num8 /= (int)b;
						b2 = 8;
						while (b4 == 0)
						{
							b4 = (byte)(num8 % (int)b);
							num8 /= (int)b;
							b2 = (byte)(b2 + 1);
						}
					}
					else
					{
						b4 = (byte)(num9 % (int)b);
						num9 /= (int)b;
						b2 = 12;
						while (b4 == 0)
						{
							b4 = (byte)(num9 % (int)b);
							num9 /= (int)b;
							b2 = (byte)(b2 + 1);
						}
					}
				}
				else if (num2 % 2 == 0)
				{
					num4 = (long)(d2 % d);
					num5 = (long)(d2 / d);
					num6 = (int)(num4 % num3);
					num7 = (int)(num4 / num3);
					if (num5 > 0)
					{
						num8 = (int)(num5 % num3);
						num9 = (int)(num5 / num3);
					}
					b4 = (byte)(num6 % (int)b);
					num6 /= (int)b;
					b3 = (byte)(num2 / 2);
				}
				else
				{
					decimal d3 = new decimal(1000000000000000L);
					long num10 = 10000000L;
					num4 = (long)(d2 % d3);
					num5 = (long)(d2 / d3);
					num6 = (int)(num4 % num10);
					num7 = (int)(num4 / num10);
					if (num5 > 0)
					{
						num8 = (int)(num5 % num3);
						num9 = (int)(num5 / num3);
					}
					b4 = (byte)(num6 % 10 * 10);
					num6 /= 10;
					b3 = (byte)(num2 / 2 + 1);
				}
				int num11 = 0;
				byte[] array = new byte[22];
				if (flag)
				{
					array[num11] = (byte)(101 - b4);
				}
				else
				{
					array[num11] = (byte)(b4 + 1);
				}
				num11++;
				while (num6 > 0)
				{
					b4 = (byte)(num6 % (int)b);
					num6 /= (int)b;
					if (flag)
					{
						array[num11] = (byte)(101 - b4);
					}
					else
					{
						array[num11] = (byte)(b4 + 1);
					}
					num11++;
					b2 = (byte)(b2 + 1);
				}
				if (num7 > 0)
				{
					while (b2 < 3)
					{
						if (flag)
						{
							array[num11] = 101;
						}
						else
						{
							array[num11] = 1;
						}
						num11++;
						b2 = (byte)(b2 + 1);
					}
				}
				while (num7 > 0)
				{
					b4 = (byte)(num7 % (int)b);
					num7 /= (int)b;
					if (flag)
					{
						array[num11] = (byte)(101 - b4);
					}
					else
					{
						array[num11] = (byte)(b4 + 1);
					}
					num11++;
					b2 = (byte)(b2 + 1);
				}
				if (num8 > 0)
				{
					while (b2 < 7)
					{
						if (flag)
						{
							array[num11] = 101;
						}
						else
						{
							array[num11] = 1;
						}
						num11++;
						b2 = (byte)(b2 + 1);
					}
				}
				while (num8 > 0)
				{
					b4 = (byte)(num8 % (int)b);
					num8 /= (int)b;
					if (flag)
					{
						array[num11] = (byte)(101 - b4);
					}
					else
					{
						array[num11] = (byte)(b4 + 1);
					}
					num11++;
					b2 = (byte)(b2 + 1);
				}
				if (num9 > 0)
				{
					while (b2 < 11)
					{
						if (flag)
						{
							array[num11] = 101;
						}
						else
						{
							array[num11] = 1;
						}
						num11++;
						b2 = (byte)(b2 + 1);
					}
				}
				while (num9 > 0)
				{
					b4 = (byte)(num9 % (int)b);
					num9 /= (int)b;
					if (flag)
					{
						array[num11] = (byte)(101 - b4);
					}
					else
					{
						array[num11] = (byte)(b4 + 1);
					}
					num11++;
					b2 = (byte)(b2 + 1);
				}
				b2 = ((!flag) ? ((byte)(b2 + 193 - b3)) : ((byte)(62 - b2 + b3)));
				if (flag)
				{
					bytes[0] = (byte)(num11 + 2);
				}
				else
				{
					bytes[0] = (byte)(num11 + 1);
				}
				bytes[1] = b2;
				int num12 = 0;
				num12 = 2;
				while (num11 > 0)
				{
					bytes[num12] = array[num11 - 1];
					num12++;
					num11--;
				}
				if (flag)
				{
					bytes[num12] = 102;
				}
			}
			catch (Exception ex)
			{
				OracleException.HandleError(OracleTraceLevel.Private, OracleTraceTag.Error, OracleTraceClassName.DecimalConv, OracleTraceFuncName.GetBytes, ex);
				throw;
			}
			finally
			{
				if (ProviderConfig.m_bTraceLevelPrivate)
				{
					Trace.Write(OracleTraceLevel.Private, OracleTraceTag.Exit, OracleTraceClassName.DecimalConv, OracleTraceFuncName.GetBytes);
				}
			}
		}

		internal static byte[] FromString(string stringRep, out bool isPositive, out bool isZero, out bool isInfinity, out bool hasDecimalPoint)
		{
			isPositive = true;
			isZero = (isInfinity = (hasDecimalPoint = false));
			if (stringRep == null)
			{
				throw new ArgumentNullException();
			}
			string text = stringRep.Trim();
			if (text.Length == 0)
			{
				throw new FormatException();
			}
			if (isZero = text.Equals("0"))
			{
				return OracleNumberCore.GetZeroByteRep();
			}
			if (text[0] == '-' || text[0] == '+')
			{
				isPositive = text[0] != '-';
				text = text.Substring(1).TrimStart();
			}
			if (isInfinity = text.Equals("~"))
			{
				if (!isPositive)
				{
					return OracleNumberCore.GetNegativeInfinityByteRep();
				}
				return OracleNumberCore.GetPositiveInfinityByteRep();
			}
			string[] array = text.Split(exponent, 2);
			string text2 = array[0].TrimEnd();
			if (array.Length == 2)
			{
				throw new FormatException();
			}
			array = text2.Split(dot);
			if (array.Length > 2)
			{
				throw new FormatException();
			}
			string text3 = array[0];
			if (!string.IsNullOrEmpty(text3))
			{
				text3 = text3.TrimStart("0"[0]);
			}
			int num = text3?.Length ?? 0;
			bool flag = num > 0;
			string text4 = null;
			int num2 = 0;
			bool flag2 = false;
			if (array.Length == 2)
			{
				text4 = array[1];
				if (!string.IsNullOrEmpty(text4))
				{
					text4 = text4.TrimEnd("0"[0]);
				}
				num2 = text4?.Length ?? 0;
				flag2 = (hasDecimalPoint = num2 > 0);
			}
			if (isZero = !(flag || flag2))
			{
				return OracleNumberCore.GetZeroByteRep();
			}
			List<byte> list = new List<byte>(21);
			int num3 = 20;
			bool flag3 = false;
			bool flag4 = false;
			int num4 = 0;
			if (flag)
			{
				int i = 0;
				if (!flag2)
				{
					text3 = text3.TrimEnd("0"[0]);
					num4 = num - text3.Length;
					num = text3.Length;
					if (num4 % 2 != 0)
					{
						text3 += "0";
						num++;
						num4--;
					}
				}
				if (num >= 40)
				{
					byte b = byte.Parse(text3[40].ToString());
					flag4 = b >= 5;
					num4 += num - 40;
					num = 40;
					if (num4 % 2 != 0)
					{
						num--;
						num4++;
					}
					text3 = text3.Substring(0, num);
				}
				if (num % 2 != 0)
				{
					byte b = byte.Parse(text3[i].ToString());
					b = ((!isPositive) ? ((byte)(101 - b)) : ((byte)(b + 1)));
					list.Add(b);
					num3--;
					i = 1;
				}
				for (; num > i; i += 2)
				{
					if (--num3 < 0)
					{
						flag3 = true;
						break;
					}
					byte b = byte.Parse(text3.Substring(i, 2));
					b = ((!isPositive) ? ((byte)(101 - b)) : ((byte)(b + 1)));
					list.Add(b);
				}
			}
			int count = list.Count;
			int num5 = 0;
			if (flag2 && !flag3)
			{
				int i = 0;
				if (!flag)
				{
					text4 = text4.TrimStart("0"[0]);
					num5 = num2 - text4.Length;
					num2 = text4.Length;
					if (num5 % 2 != 0)
					{
						text4 = "0" + text4;
						num2++;
						num5--;
					}
					if (num2 >= 40)
					{
						byte b = byte.Parse(text4[40].ToString());
						flag4 = b >= 5;
					}
				}
				if (flag2 && flag && num2 + num >= 40)
				{
					byte b = byte.Parse(text4[40 - num].ToString());
					flag4 = b >= 5;
				}
				if (num2 % 2 != 0)
				{
					text4 += "0";
					num2++;
				}
				for (; num2 > i; i += 2)
				{
					if (--num3 < 0)
					{
						flag3 = true;
						break;
					}
					byte b = byte.Parse(text4.Substring(i, 2));
					b = ((!isPositive) ? ((byte)(101 - b)) : ((byte)(b + 1)));
					list.Add(b);
				}
			}
			bool flag5 = false;
			if (flag4)
			{
				byte[] array2 = list.ToArray();
				int num6 = 0;
				if (isPositive)
				{
					int num7 = array2.Length - 1;
					while (num7 >= 0)
					{
						byte b = array2[num7];
						num6 = b + 1;
						if (num6 > 100)
						{
							list.RemoveAt(num7);
							num7--;
							continue;
						}
						list[num7] = (byte)num6;
						break;
					}
					if (num7 < 0 && num6 > 100)
					{
						list.Add(2);
						flag5 = true;
					}
				}
				else
				{
					int num7 = array2.Length - 1;
					while (num7 >= 0)
					{
						byte b = array2[num7];
						num6 = b - 1;
						if (num6 < 2)
						{
							list.RemoveAt(num7);
							num7--;
							continue;
						}
						list[num7] = (byte)num6;
						break;
					}
					if (num7 < 0 && num6 < 2)
					{
						list.Add(100);
						flag5 = true;
					}
				}
			}
			if (!isPositive && list.Count < 20)
			{
				list.Add(102);
			}
			int num8 = count - 1;
			if (!flag2)
			{
				num8 += num4 / 2;
			}
			else if (!flag)
			{
				num8 -= num5 / 2;
			}
			if (flag5)
			{
				num8++;
			}
			if (num8 > 62)
			{
				throw new OverflowException();
			}
			if (num8 < -65)
			{
				return OracleNumberCore.GetZeroByteRep();
			}
			num8 = ((!isPositive) ? ((byte)(62 - num8)) : (num8 + 193));
			list.Insert(0, (byte)num8);
			return list.ToArray();
		}

		internal static string ToString(byte[] bytes, char decimalSeparator = '.')
		{
			if (bytes == null || bytes.Length == 0 || bytes.Length > 21)
			{
				return null;
			}
			if (OracleNumberCore.IsZero(bytes))
			{
				return "0";
			}
			bool flag = !OracleNumberCore.IsPositive(bytes);
			if (OracleNumberCore.IsInfinity(bytes))
			{
				if (!flag)
				{
					return "~";
				}
				return "-~";
			}
			int num = bytes.Length - 1;
			if (flag && bytes[num] == 102)
			{
				num--;
			}
			int num2 = 0;
			int num3 = num;
			int num4 = 0;
			num4 = ((!flag) ? (bytes[num2] - 193) : (62 - bytes[num2]));
			bool flag2 = num4 < 0;
			string text = null;
			StringBuilder stringBuilder = new StringBuilder();
			for (int i = 1; i <= num3; i++)
			{
				int num5 = bytes[i];
				stringBuilder.Append(((!flag) ? (num5 - 1) : (101 - num5)).ToString("D2"));
			}
			if (flag2)
			{
				int num6 = (num4 + 1) * -1 * 2;
				if (num6 > 0)
				{
					stringBuilder.Insert(0, "0", num6);
				}
				stringBuilder.Insert(0, "0" + decimalSeparator);
				text = stringBuilder.ToString().TrimEnd("0"[0]);
			}
			else
			{
				int num7 = num4 + 1;
				int num8 = num - num7;
				if (num8 > 0)
				{
					int num9 = num7 * 2;
					if (num9 < stringBuilder.Length)
					{
						stringBuilder.Insert(num9, decimalSeparator);
					}
					text = stringBuilder.ToString().Trim("0"[0]);
				}
				else
				{
					if (num8 < 0)
					{
						int num10 = num8 * -1 * 2;
						if (num10 > 0)
						{
							stringBuilder.Append("0"[0], num10);
						}
					}
					text = stringBuilder.ToString().TrimStart("0"[0]);
				}
			}
			if (flag)
			{
				text = "-" + text;
			}
			return text;
		}
	}
}
